package com.melon.utils;

import org.apache.shiro.codec.Base64;
import org.apache.shiro.crypto.hash.Md5Hash;

public class EncryptUtil {

	/**
	 * base64加密
	 * @param str
	 * @return
	 */
	public static String encBase64(String str){
		return Base64.encodeToString(str.getBytes());
	}

	/**
	 * base64解密
	 * @param str
	 * @return
	 */
	public static String decBase64(String str){
		return Base64.decodeToString(str);
	}

	/**
	 * Md5加密
	 * @param str
	 * @param salt
	 * @return
	 */
	public static String md5(String str,String salt){
		return new Md5Hash(str,salt,2).toString();
	}

	public static void main(String[] args) {
		String password="1234";
		System.out.println("Base64加密："+ EncryptUtil.encBase64(password));
		System.out.println("Base64解密："+ EncryptUtil.decBase64(EncryptUtil.encBase64(password)));

		System.out.println("Md5加密："+ EncryptUtil.md5(password, "verygood"));
	}
}

